<!DOCTYPE HTML>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="武威涛哥的博客">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <meta name="theme-version" content="1.2.3">
    <meta name="root" content="/">
    <link rel="dns-prefetch" href="https://jaredtao.github.io">
    <!--SEO-->

    <meta name="keywords" content="Qt,Qml,QtQuick,特效">


    <meta name="description" content="
简介
关于文章
棋盘效果预览
实现原理

简介这是《Qml特效-进场动画》系列文章的第11篇，涛哥将会教大家一些Qml进场动画相关的知识。
进场动画效果 参考了WPS版ppt的动画，基本效果已...">



<meta name="robots" content="all">
<meta name="google" content="all">
<meta name="googlebot" content="all">
<meta name="verify" content="all">

    <!--Title-->

<title>
    
    Qml特效11-进场动画-棋盘 |
    
    武威涛哥的博客
</title>

    <link rel="alternate" href="/atom.xml" title="武威涛哥的博客" type="application/atom+xml">


    <link rel="icon" href="/favicon.ico">

    



<link rel="stylesheet" href="/css/bootstrap.min.css?rev=3.3.7">
<link rel="stylesheet" href="/css/font-awesome.min.css?rev=4.7.0">
<link rel="stylesheet" href="/css/style.css?rev=@@hash">




    
	<div class="hide">
		<script type="text/javascript">
			var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
		</script>
	</div>






    

    <script>
        (function(){
            var bp = document.createElement('script');
            var curProtocol = window.location.protocol.split(':')[0];
            if (curProtocol === 'https') {
                bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
            }
            else {
                bp.src = 'http://push.zhanzhang.baidu.com/push.js';
            }
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(bp, s);
        })();
    </script>

</head>

</html>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<body>
    <header class="main-header"  style="background-image:url(http://snippet.shenliyang.com/img/banner.jpg)"  >
    <div class="main-header-box">
        <a class="header-avatar" href="/" title='JaredTao'>
            <img src="/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
        </a>
        <div class="branding">
        	<!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
                <h2> 传承工匠精神 </h2>
            
    	</div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
                    <span class="sr-only"></span>
                        <i class="fa fa-bars"></i>
                    </span>
                    <a class="navbar-brand" href="https://jaredtao.github.io">武威涛哥的博客</a>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                            <li role="presentation" class="text-center">
                                <a href="/"><i class="fa "></i>首页</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/Qml组件化编程/"><i class="fa "></i>Qml组件化编程</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/Qml特效/"><i class="fa "></i>Qml特效</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/Qt进阶之路/"><i class="fa "></i>Qt进阶之路</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/C-修炼之路/"><i class="fa "></i>C++修炼之路</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/武威故事/"><i class="fa "></i>武威故事</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/archives/"><i class="fa "></i>时间轴</a>
                            </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="Qml特效11-进场动画-棋盘">
            
	            Qml特效11-进场动画-棋盘
            
        </h1>
        <div class="post-meta">
    
        <span class="categories-meta fa-wrap">
            <i class="fa fa-folder-open-o"></i>
            <a class="category-link" href="/categories/Qml特效/">Qml特效</a>
        </span>
    

    
        <span class="fa-wrap">
            <i class="fa fa-tags"></i>
            <span class="tags-meta">
                
                    <a class="tag-link" href="/tags/Qml/">Qml</a> <a class="tag-link" href="/tags/Qt/">Qt</a> <a class="tag-link" href="/tags/QtQuick/">QtQuick</a> <a class="tag-link" href="/tags/特效/">特效</a>
                
            </span>
        </span>
    

    
        
        <span class="fa-wrap">
            <i class="fa fa-clock-o"></i>
            <span class="date-meta">2019/06/09</span>
        </span>
        
            <span class="fa-wrap">
                <i class="fa fa-eye"></i>
                <span id="busuanzi_value_page_pv"></span>
            </span>
        
    
</div>
            
            
    </div>
    
    <div id="post-gallery">
        
          <img src="/img/avatar.jpg" alt="gallery-img" class="gallery">
        
    </div>

    <div class="post-body post-content">
        <ul>
<li><a href="#%E7%AE%80%E4%BB%8B">简介</a></li>
<li><a href="#%E5%85%B3%E4%BA%8E%E6%96%87%E7%AB%A0">关于文章</a></li>
<li><a href="#%E6%A3%8B%E7%9B%98%E6%95%88%E6%9E%9C%E9%A2%84%E8%A7%88">棋盘效果预览</a></li>
<li><a href="#%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86">实现原理</a></li>
</ul>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>这是《Qml特效-进场动画》系列文章的第11篇，涛哥将会教大家一些Qml进场动画相关的知识。</p>
<p>进场动画效果 参考了WPS版ppt的动画，基本效果已经全部实现，可以到github TaoQuick项目中预览：</p>
<p><a href="https://github.com/jaredtao/TaoQuick/blob/master/Preview-animation.md" target="_blank" rel="noopener">进场动画预览</a></p>
<h2 id="关于文章"><a href="#关于文章" class="headerlink" title="关于文章"></a>关于文章</h2><p>文章主要发布在<a href="https://jaredtao.github.io">涛哥的博客</a> 和 <a href="https://zhuanlan.zhihu.com/TaoQt" target="_blank" rel="noopener">涛哥的知乎专栏-Qt进阶之路</a></p>
<h2 id="棋盘效果预览"><a href="#棋盘效果预览" class="headerlink" title="棋盘效果预览"></a>棋盘效果预览</h2><p>棋盘效果，支持向右、向下两个方向</p>
<p><img src="/images/Animation/11.gif" alt></p>
<h2 id="实现原理"><a href="#实现原理" class="headerlink" title="实现原理"></a>实现原理</h2><p>通过数值动画，控制百分比属性percent从0 到100变化</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">import QtQuick 2.12</span><br><span class="line">import QtQuick.Controls 2.12</span><br><span class="line">ShaderEffect &#123;</span><br><span class="line">    ...</span><br><span class="line">    //枚举声明四种方向</span><br><span class="line">    enum Direct &#123;</span><br><span class="line">        ToRight = 0,</span><br><span class="line">        ToBottom = 1</span><br><span class="line">    &#125;</span><br><span class="line">    property int dir : ABoard.Direct.ToRight</span><br><span class="line">    property int percent: 0</span><br><span class="line">    opacity: percent &gt; 0 ? 1 : 0</span><br><span class="line">    NumberAnimation &#123;</span><br><span class="line">        id: animation</span><br><span class="line">        target: r</span><br><span class="line">        property: &quot;percent&quot;</span><br><span class="line">        from: 0</span><br><span class="line">        to: 100</span><br><span class="line">        alwaysRunToEnd: true</span><br><span class="line">        loops: 1</span><br><span class="line">        duration: 1000</span><br><span class="line">    &#125;</span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在Shader中，使用glsl片段着色器实现像素的控制：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">    fragmentShader: TCommon.fragmentShaderCommon + (dir === ABoard.Direct.ToRight ? "</span><br><span class="line">        <span class="keyword">in</span>  <span class="type">vec2</span> qt_TexCoord0;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">float</span> qt_Opacity;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">sampler2D</span> effectSource;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> dir;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> percent;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> rowCount;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> columnCount;</span><br><span class="line">        <span class="keyword">out</span> <span class="type">vec4</span> fragColor;</span><br><span class="line">        <span class="type">void</span> main()</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="type">vec4</span> color = <span class="built_in">texture2D</span>(effectSource, qt_TexCoord0);</span><br><span class="line">            <span class="type">int</span> xlen = <span class="number">100</span> / columnCount;</span><br><span class="line">            <span class="type">int</span> ylen = <span class="number">100</span> / rowCount;</span><br><span class="line">            <span class="type">float</span> p = <span class="type">float</span>(percent) / <span class="number">100.0</span>;</span><br><span class="line">            <span class="type">int</span> x = <span class="type">int</span>(qt_TexCoord0.x * <span class="number">100.0</span>);</span><br><span class="line">            <span class="type">int</span> y = <span class="type">int</span>(qt_TexCoord0.y * <span class="number">100.0</span>);</span><br><span class="line">            <span class="type">float</span> alpha = <span class="number">0.0</span>;</span><br><span class="line">            <span class="type">int</span> sx = x / xlen;</span><br><span class="line">            <span class="type">int</span> sy = y / ylen;</span><br><span class="line">            <span class="type">int</span> xOffset = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">if</span> (sy % <span class="number">2</span> != <span class="number">0</span>) &#123;</span><br><span class="line">                xOffset = xlen / <span class="number">2</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (sx * xlen &lt;= x + xOffset &amp;&amp; (x + xOffset) % xlen &lt;= <span class="type">int</span>(<span class="type">float</span>(xlen) * p) ) &#123;</span><br><span class="line">                alpha = <span class="number">1.0</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            alpha *= qt_Opacity;</span><br><span class="line">            fragColor = <span class="type">vec4</span>(color.rgb * alpha, alpha);</span><br><span class="line">       &#125;</span><br><span class="line">" : "</span><br><span class="line">        <span class="keyword">in</span>  <span class="type">vec2</span> qt_TexCoord0;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">float</span> qt_Opacity;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">sampler2D</span> effectSource;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> dir;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> percent;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> rowCount;</span><br><span class="line">        <span class="keyword">uniform</span> <span class="type">int</span> columnCount;</span><br><span class="line">        <span class="keyword">out</span> <span class="type">vec4</span> fragColor;</span><br><span class="line">        <span class="type">void</span> main()</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="type">vec4</span> color = <span class="built_in">texture2D</span>(effectSource, qt_TexCoord0);</span><br><span class="line">            <span class="type">int</span> xlen = <span class="number">100</span> / columnCount;</span><br><span class="line">            <span class="type">int</span> ylen = <span class="number">100</span> / rowCount;</span><br><span class="line">            <span class="type">float</span> p = <span class="type">float</span>(percent) / <span class="number">100.0</span>;</span><br><span class="line">            <span class="type">int</span> x = <span class="type">int</span>(qt_TexCoord0.x * <span class="number">100.0</span>);</span><br><span class="line">            <span class="type">int</span> y = <span class="type">int</span>(qt_TexCoord0.y * <span class="number">100.0</span>);</span><br><span class="line">            <span class="type">float</span> alpha = <span class="number">0.0</span>;</span><br><span class="line">            <span class="type">int</span> sx = x / xlen;</span><br><span class="line">            <span class="type">int</span> sy = y / ylen;</span><br><span class="line">            <span class="type">int</span> yOffset = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">if</span> (sx % <span class="number">2</span> != <span class="number">0</span>) &#123;</span><br><span class="line">                yOffset = ylen / <span class="number">2</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (sy * ylen &lt;= y + yOffset &amp;&amp; (y + yOffset) % ylen &lt;= <span class="type">int</span>(<span class="type">float</span>(ylen) * p) ) &#123;</span><br><span class="line">                alpha = <span class="number">1.0</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            alpha *= qt_Opacity;</span><br><span class="line">            fragColor = <span class="type">vec4</span>(color.rgb * alpha, alpha);</span><br><span class="line">       &#125;</span><br><span class="line">")</span><br></pre></td></tr></table></figure>


    </div>
    
        <div class="reward" ontouchstart>
    <div class="reward-wrap">赏
        <div class="reward-box">
            
                <span class="reward-type">
                    <img class="alipay" src="/img/zhifubao.jpg"><b>支付宝打赏</b>
                </span>
            
            
                <span class="reward-type">
                    <img class="wechat" src="/img/weixin.jpg"><b>微信打赏</b>
                </span>
            
        </div>
    </div>
    <p class="reward-tip">赞赏是不耍流氓的鼓励</p>
</div>


    
    <div class="post-footer">
        <div>
            
                转载声明：文章采用<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a>进行许可, 转载请注明出处 © <a href="https://jaredtao.github.io" target="_blank">武威的涛哥</a>
            
        </div>
        <div>
            
        </div>
    </div>
</article>

<div class="article-nav prev-next-wrap clearfix">
    
        <a href="/2019/06/09/Qml特效12-进场动画-溶解/" class="pre-post btn btn-default" title='Qml特效12-进场动画-溶解'>
            <i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
            <span class="hidden-xs">Qml特效12-进场动画-溶解</span>
        </a>
    
    
        <a href="/2019/06/09/Qml特效10-进场动画-轮子/" class="next-post btn btn-default" title='Qml特效10-进场动画-轮子'>
            <span class="hidden-lg">下一篇</span>
            <span class="hidden-xs">Qml特效10-进场动画-轮子</span><i class="fa fa-angle-right fa-fw"></i>
        </a>
    
</div>


    <div id="comments">
        
	
    <div id="vcomments" class="valine"></div>
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="/assets/valine.min.js"></script>

    <script>
        new Valine({
            av: AV,
            el: '#vcomments',
            appId: 'qegD4552u6FU9HoNDvRsonko-gzGzoHsz',
            appKey: 'eitB2FV5n2qyMHcDM7x6EQpt',
            placeholder: '说点什么吧',
            notify: false,
            verify: false,
            avatar: 'mm',
            meta: 'nick,mail'.split(','),
            pageSize: '10',
            path: window.location.pathname,
            lang: 'zh-CN'.toLowerCase()
        })
    </script>


    </div>





                </main>
                
                    <aside id="article-toc" role="navigation" class="col-md-4">
    <div class="widget">
        <h3 class="title">文章目录</h3>
        
            <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#简介"><span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#关于文章"><span class="toc-text">关于文章</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#棋盘效果预览"><span class="toc-text">棋盘效果预览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#实现原理"><span class="toc-text">实现原理</span></a></li></ol>
        
    </div>
</aside>

                
            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>

<a id="back-to-top" class="icon-btn hide">
	<i class="fa fa-chevron-up"></i>
</a>




    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="busuanzi">
    
        访问量:
        <strong id="busuanzi_value_site_pv">
            <i class="fa fa-spinner fa-spin"></i>
        </strong>
        &nbsp; | &nbsp;
        访客数:
        <strong id="busuanzi_value_site_uv">
            <i class="fa fa-spinner fa-spin"></i>
        </strong>
    
</div>

            </div>
            <div class="col-sm-12">
                <span>Copyright &copy;
                    2019
                    
                </span> |
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> |
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>




    <script src="/assets/tagcanvas.min.js?rev=2.9"></script>
    <script>
        var tagOption = {
            textColour: '#444', // 字体颜色
            outlineMethod: 'block', // 选中模式
            outlineColour: '#FFDAB9', // 选中模式的颜色
            interval: 30 || 30, // 动画帧之间的时间间隔，值越大，转动幅度越大
            textHeight: 13,
            outlineRadius: 3,
            freezeActive: true || '', // 选中的标签是否继续滚动
            frontSelect: true || '', // 不选标签云后部的标签
            initial: [0.1, -0.1],
            depth: 0.5,
            decel: 0.95,
            maxSpeed: 0.03,
            reverse: true || '', // 是否反向触发
            fadeIn: 500, // 进入动画时间
            wheelZoom: false || '' // 是否启用鼠标滚轮
        }
        TagCanvas.Start('tag-cloud-3d','',tagOption);
    </script>



    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


<script src="/js/app.js?rev=@@hash"></script>

</body>
</html>